# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-cucumber-html-formatter
pkgver=20.4.0
pkgrel=1
pkgdesc="HTML formatter for Cucumber"
arch=(any)
url='https://github.com/cucumber/html-formatter/tree/main/ruby'
license=(MIT)
depends=(ruby-cucumber-messages)
makedepends=(npm ruby-rake ruby-rspec ruby-cucumber-compatibility-kit)
options=(!emptydirs)
source=(https://github.com/cucumber/html-formatter/archive/v$pkgver/cucumber-html-formatter-$pkgver.tar.gz)
sha256sums=('408832146c76d148b43ec10631f6c0169a2ca75ed9c3a3d585a432bcc08d66eb')

prepare() {
  cd html-formatter-$pkgver/ruby
  sed -r -e 's|~>|>=|g' -e "s/, '< 22.1'//" -i cucumber-html-formatter.gemspec
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd html-formatter-$pkgver
  make prepare
  cd ruby
  gem build cucumber-html-formatter.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    cucumber-html-formatter-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd html-formatter-$pkgver/ruby
  GEM_HOME="tmp_install/$_gemdir" rake
}

package() {
  cd html-formatter-$pkgver/ruby
  cp -a tmp_install/* "$pkgdir"/
}
